﻿@model KRM.Core.tblLoad
<script>
    $(document).ready(function() {
        vehiclechange($("#VehicleID").val());
        $('.datetimepicker').datetimepicker({
            language: 'en',
            pick12HourFormat: true
        });

        $("#fr-confirmload").submit(function () {
            if (confirm("Are you sure you want to Confirm Load: @Model.LoadCode ?")) {
                var baynumber = $("#baynumber").val();
                var result = false;
                if (baynumber == "")
                {
                    if (confirm("Bay Number is null, you are sure to continue?")) {
                        result = true;
                    }
                }
                else if (isNaN(baynumber)) {
                    if (confirm("Bay Number isn't a number, you are sure to continue?")) {
                        result = true;
                    }
                } else {
                    result = true;
                }
                if (result == true) {
                    var serializedForm = $(this).serialize();
                    App.blockUI($('.loadcreatorloaddetail'), false);
                    $.ajax({
                        type: 'POST',
                        url: '/load/confirmload',
                        data: serializedForm,
                        success: function (data) {
                            if (data == "") {
                                confirmloadcontinue(serializedForm);
                            } else {
                                if (confirm(data)) {
                                    confirmloadcontinue(serializedForm);
                                }
                            }
                            App.unblockUI($('.loadcreatorloaddetail'));
                        }
                    });
                }
                return false;
            }
        });
    });
    function vehiclechange(vehicleid) {
        $.ajax({            
            url: "/load/vehiclechange?vehicleid=" + vehicleid,
            success: function(data) {
                $(".vehiclemaxweight").html(data);
            }
        });
    }
    function confirmloadcontinue(serializedForm) {
        $.ajax({            
            url: "/load/confirmload1",
            data: serializedForm,
            success:function() {
                refreshload();
                loadcreatorloaditem(@Model.LoadID);
            }
        });
    }
</script>
<form action="/load/confirmload" method="POST" class="margin0" id="fr-confirmload">
    <input type="hidden" name="loadid" value="@Model.LoadID"/>
    <div class="row-fluid">
        <div class="span2">
            <h3>@Model.LoadCode</h3>
            <p>Load status: @Model.LP_LoadStatus.LoadStatus</p>
        </div>
        <div class="span10">
            <div class="row-fluid">
                <div class="span2">Items Qty:</div>
                <div class="span1">@Model.GetLoadItemDetails().Count()</div>
                <div class="span1">Vehicle</div>
                <div class="span2">
                    @Html.DropDownList("VehicleID", null, new { @class = "input-block-level", onchange = "vehiclechange(this.value)" })
                </div>
                <div class="span2">Despatched Date:</div>
                <div class="span2">
                    <div class="input-append datetimepicker">
                        <input data-format="dd/MM/yyyy" type="text" name="DespatchDate" style="width: 65%" value="@string.Format("{0:dd/MM/yyyy}", Model.DespatchDate)">
                        <span class="add-on">
                            <i data-time-icon="icon-time" data-date-icon="icon-calendar" class="icon-calendar"></i>
                        </span>
                    </div>
                </div>
            </div>
            <div class="row-fluid">
                <div class="span2">Packages Qty:</div>
                <div class="span1">@Model.GetLoadItemDetails().Sum(item => item.Packages)</div>
                <div class="span3">Vehicle max weight: <span class="vehiclemaxweight">@Model.GetLoadItemDetails().Sum(item => item.WeightKG)</span></div>
                <div class="span2">Delivery Date:</div>
                <div class="span2">
                    <div class="input-append datetimepicker">
                        <input data-format="dd/MM/yyyy" type="text" name="PlannedDeliveryDate" style="width: 65%" value="@string.Format("{0:dd/MM/yyyy}", Model.PlannedDeliveryDate)">
                        <span class="add-on">
                            <i data-time-icon="icon-time" data-date-icon="icon-calendar" class="icon-calendar"></i>
                        </span>
                    </div>
                </div>
            </div>
            <div class="row-fluid">
                <div class="span2">Total Weight:</div>
                <div class="span1">@Model.GetLoadItemDetails().Sum(item => item.WeightKG)</div>
                <div class="span1">Driver</div>
                <div class="span2">
                    @Html.DropDownList("DriverID", null, new { @class = "input-block-level" })
                </div>
                <div class="span2">Bay Number:</div>
                <div class="span2">
                    <input type="text" class="input-block-level" name="baynumber" id="baynumber" />
                </div>
                <div class="span2">
                    <input type="submit" class="btn btn-primary" value="Confirm Load" style="width: 100%" />
                </div>
            </div>
        </div>
    </div>
</form>